<cfcomponent extends="assets.calgrants.com.Base">

	<cfscript>
        import assets.calgrants.com.bo.City;
	</cfscript>
	
	<cffunction name="get" access="public" output="false" returntype="assets.calgrants.com.bo.City">
		<cfargument name="City_ID" type="numeric" required="true" />
		<cfscript>
			if (arguments.City_ID gt 0) {
				local.loadArgs = {};
				local.loadArgs.obj = new City();
				StructAppend(local.loadArgs, QueryToStruct(read(argumentCollection = arguments))[1]);
				return load(argumentCollection = local.loadArgs);
			} else {
				return new City();
			}
		</cfscript>
	</cffunction>
	
	<cffunction name="load" access="public" output="false" returntype="assets.calgrants.com.bo.City">
		<cfargument name="obj" type="assets.calgrants.com.bo.City" required="true" />
		<cfscript>
			local.obj = arguments.obj;
			if (IsDefined("arguments.City_ID")) {
				local.obj.setCity_ID(arguments.City_ID);
			}
			if (IsDefined("arguments.Deleted")) {
				local.obj.setDeleted(arguments.Deleted);
			}
			if (IsDefined("arguments.City")) {
				local.obj.setCity(arguments.City); 
			}
			if (IsDefined("arguments.Zip")) {
				local.obj.setZip_Code(arguments.Zip);
			}
			if (IsDefined("arguments.County_ID")) {
				local.obj.setCounty_ID(arguments.County_ID);
			}
			if (IsDefined("arguments.Date_Created")) {
				local.obj.setDate_Created(arguments.Date_Created);
			}
			return local.obj;
		</cfscript>
	</cffunction>

	<cffunction name="read" access="public" output="false" returntype="any">
		<cfargument name="City_ID" required="false" default="" />
		<cfargument name="Deleted" required="false" default="0" />
		<cfargument name="City" required="false" default="" />
		<cfargument name="Zip" required="false" default="" />
		<cfargument name="County_ID" required="false" default="" />
		<cfargument name="Date_Created" required="false" default="" />

		<cfset var recs = "">
		<cfstoredproc datasource="#getDatasource()#" procedure="readCity">
			<cfprocparam value="#arguments.City_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.City_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Deleted#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Deleted)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.City#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.City)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Zip#" cfsqltype="CF_SQL_CHAR" null="#IIf(Len(Trim(arguments.Zip)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.County_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.County_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Date_Created#" cfsqltype="CF_SQL_TIMESTAMP" null="#IIf(Len(Trim(arguments.Date_Created)) eq 0, true, false)#" />
			<cfprocresult name="recs" />
		</cfstoredproc>
		<cfreturn recs />
	</cffunction>

	<cffunction name="save" access="public" output="false" returntype="any">
		<cfargument name="city" required="true" type="assets.calgrants.com.bo.City" />

		<cfstoredproc datasource="#getDatasource()#" procedure="saveCity">
			<cfprocparam value="#city.getCity_ID()#" cfsqltype="CF_SQL_INTEGER" variable="id" type="inout" null="false" />
			<cfprocparam value="#city.getDeleted()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#city.getCity()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#city.getZip()#" cfsqltype="CF_SQL_CHAR" null="false" />
			<cfprocparam value="#city.getCounty_ID()#" cfsqltype="CF_SQL_INTEGER" null="false" />
		</cfstoredproc>
		<cfreturn id />
	</cffunction>

	<cffunction name="destroy" access="public" output="false" returntype="any">
		<cfargument name="City_ID" required="true" />

		<cfstoredproc datasource="#getDatasource()#" procedure="destroyCity">
			<cfprocparam value="#arguments.City_ID#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="true" cfsqltype="CF_SQL_BIT" null="false" />
		</cfstoredproc>
		<cfreturn true />
	</cffunction>

</cfcomponent>

